package math.probability;

import java.util.ArrayList;
import java.util.Random;

public class ExpDistribution extends ProbDistribution {
	private Double l;

	
	public ExpDistribution(Double l) {
		this.l = l;
	}
	
	public ExpDistribution() {
		this.l = 1.0;
	}
	
	
	public ArrayList<Double> getSample(int n) {
		Random r = new Random();
		ArrayList<Double> sample = new ArrayList<Double>();
		for (int i = 0; i < n; i++) {
			sample.add(-Math.log(r.nextDouble())/l);
		}
		return sample;
	}
	
	public ArrayList<Double> getSample(int n, Random r) {
		ArrayList<Double> sample = new ArrayList<Double>();
		for (int i = 0; i < n; i++) {
			sample.add(-Math.log(r.nextDouble())/l);
		}
		return sample;
	}
	
	public String toString() {
		return "Exp(" + String.format("%2.2f", l) + ")";
		 
	}

	@Override
	public Double getNext() {
		Random r = new Random();
		return -Math.log(r.nextDouble())/l;
	}
	
	public Double getNext(Random r) {
		return -Math.log(r.nextDouble())/l;
	}
	
	public Double getDisp() {
		return 1/(l*l);
	}
}
